<?php


namespace app\adminapi\dao\user;


use app\common\dao\BaseHotelDao;
use app\common\model\member\MemberLevel;
use app\common\model\user\UserType;

/**
 * @projectName src
 */
class UserTypeDao extends BaseHotelDao
{
    public static function add(array $params)
    {
        UserType::create([
            'type_name' => $params['type_name']
        ]);
    }

    public static function edit(array $params): bool
    {
        try {
            UserType::update([
                'id' => $params['id'],
                'type_name' => $params['type_name']
            ]);
            return true;
        } catch (\Exception $e) {
            self::setError($e->getMessage());
            return false;
        }
    }

    public static function delete(array $params)
    {
        UserType::destroy($params['id']);
    }

    public static function detail(array $params): array
    {
        return UserType::findOrEmpty($params['id'])->toArray();
    }

    public static function getAllData()
    {
        return UserType::order('id', 'desc')->select()->toArray();
    }
}